//
//  CSNewOrderReplaceVC.m
//  ProjectforHDX
//
//  Created by yinda on 16/8/22.
//  Copyright © 2016年 H.DX. All rights reserved.
//

// 客户替换服务

#import "CSNewOrderReplaceVC.h"
#import "CSNewOrderCell.h"
#import "CSNewOrderFirstCell.h"
#import "CSNewOrderUseRepairsCell.h"
#import "CSNewOrderMessageCell.h"
#import "CSNewOrderReplaceCell.h"
#import "CSNewOrderLogisticsCell.h"
#import "CSNewOrderDeliveryCell.h"
#import "ConsigneeListVC.h"

#import "CNewOrderFaultyPartsVC.h"     //获取故障件名称
#import "FailurePartsModel.h"

#import "MHScanViewController.h"

@interface CSNewOrderReplaceVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,PXAlertViewDelegate,UITextViewDelegate,UIActionSheetDelegate,UIImagePickerControllerDelegate,MWPhotoBrowserDelegate>
{
    UITableView *tabelView;     //备件管理服务
   
    UIAlertController *alertView;   //选择器
    
    //备件替换服务
    NSMutableDictionary *replacePostDic;
    NSMutableArray *replaceReceiptArray;        //收货信息左边
    NSMutableArray *replaceArray;
    NSMutableDictionary *replaceDataDic;       // 收货信息存放
    
    NSMutableDictionary *customerServiceDic;  // 客服带客户特有字段

    NSMutableDictionary *replaceFaultDataDic;  //  故障件信息存放
    NSMutableDictionary *replaceLogisticsDic;  // 物流信息存放
    NSString *message;       // 备注
    
    NSInteger selectedIndex;  //选择的那个控制器
    UITapGestureRecognizer *labelTapGestureRecognizer;
    
    MWPhoto *guzhangphoto; // 故障图片
    
    NSArray *myConsigneesArray;    // 存放的客户联系人信息
    NSArray *logisticsArray;       //存放物流信息
    UIView *shadowView;        // 阴影
    int which;
    
}

@property (nonatomic, strong) UIView *maskView;

@end

@implementation CSNewOrderReplaceVC{
    UIDatePicker *datePicker;
    UIToolbar *toolBar;
    UITextField *currentTextField;
}

- (void)getDefaultContactsAndAddress{
    [AFHttpTool postJsonDatawithUrl:@"getAddresses" parameters:nil success:^(id responseObject) {
        
        if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
            NSArray *array = [responseObject objectForKey:@"data"];
            NSLog(@"地址为%@",array);
            NSMutableArray *actionArray = [[NSMutableArray alloc]init];
            for (int i = 0; i < array.count; i++) {
                [actionArray addObject:array[i][@"address"]];
            }
            if (actionArray.count > 0) {
                [replaceDataDic setValue:actionArray[0] forKey:@"address"];
            }
            [tabelView reloadData];
        }else {
            [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
    }];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self dataConfig];
    
    [self getDefaultContactsAndAddress];
    
    [self viewFound];
    if (self.order == 1) {
        
        NSLog(@"传过来的数据%@",self.dict);
        
        //收货信息
        replaceDataDic[@"name"] = self.dict[@"customerService"][@"customerName"];
        replaceDataDic[@"user"] = self.dict[@"receiver"][@"userID"];
        replaceDataDic[@"address"] = self.dict[@"receiver"][@"address"];
        replaceDataDic[@"tel"] = [NSString stringWithFormat:@"%@ %@",self.dict[@"receiver"][@"name"],self.dict[@"receiver"][@"tel"]];
        NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[self.dict[@"receiver"][@"isUrgent"] dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
        
        
        if ([NSString stringWithFormat:@"%@",attrStr].length == 0) {
            replaceDataDic[@"isUrgent"] = [UtilCheck language:@"order.no"];
        }else if ([[NSString stringWithFormat:@"%@",attrStr] isEqualToString:@"加急"]){
            replaceDataDic[@"isUrgent"] = [UtilCheck language:@"order.yes"];
        }
        customerServiceDic[@"customerTime"] = self.dict[@"customerService"][@"customerTime"];
        customerServiceDic[@"customerID"] = self.dict[@"customerService"][@"customerID"];
        
        // 故障件信息
        for (NSDictionary *dic in self.dict[@"parts"][@"faultParts"]) {
            
            NSDictionary *myDataDic = dic[@"faultPart"];
            
            NSLog(@"%@",myDataDic);
            
            NSMutableDictionary *DataDic = [[NSMutableDictionary alloc]init];
            if ([myDataDic objectForKey:@"plateID"] == nil) {
                [DataDic setValue:@"" forKey:@"id"];
            }else {
                [DataDic setValue:[myDataDic objectForKey:@"plateID"] forKey:@"id"];
            }
            [DataDic setValue:[myDataDic objectForKey:@"rma"] forKey:@"rma"];
            [DataDic setValue:@"1" forKey:@"number"];
            [DataDic setValue:[myDataDic objectForKey:@"faultPartType"] forKey:@"faultPartType"];
            [DataDic setValue:[myDataDic objectForKey:@"plateName"] forKey:@"name"];
            [DataDic setValue:[myDataDic objectForKey:@"plateCode"] forKey:@"code"];
            [DataDic setValue:[myDataDic objectForKey:@"is_version"] forKey:@"is_version"];
            [DataDic setValue:[dic objectForKey:@"detail"] forKey:@"describe"];
            [replaceArray addObject:DataDic];
        }
        NSLog(@"故障件信息%@",replaceArray);
        
        if (self.dict[@"logistics"] == nil) {
            
        }else
        {
            // @"",@"courierID",@"",@"courierNum",@"",@"courierName", nil
            //物流信息
            [replaceLogisticsDic setValue:self.dict[@"logistics"][@"logisticsInfo"][@"courierID"] forKey:@"courierID"];
            [replaceLogisticsDic setValue:self.dict[@"logistics"][@"logisticsInfo"][@"expressCode"] forKey:@"courierNum"];
            [replaceLogisticsDic setValue:self.dict[@"logistics"][@"logisticsInfo"][@"com"] forKey:@"courierName"];
            
            NSLog(@"%@",replaceLogisticsDic);
            
        }
        //备注
        message = self.dict[@"remark"];
    }
    [self setUpImageArray];

}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    //获取通知中心单例对象
    NSNotificationCenter * centerReplace = [NSNotificationCenter defaultCenter];
    //添加当前类对象为一个观察者，name和object设置为nil，表示接收一切通知
    [centerReplace addObserver:self selector:@selector(notice:) name:@"replace" object:nil];
    [tabelView reloadData];
}
-(void)notice:(NSNotification *)sender{
    NSInteger faulttag = [sender.userInfo[@"tag"] intValue];
    
    NSString *nameString = [NSString stringWithFormat:@"%@  %@",sender.userInfo[@"name"],sender.userInfo[@"code"]];
    NSLog(@"%@",nameString);
    
    [replaceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"name"] forKey:@"name"];
    [replaceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"code"] forKey:@"code"];
    [replaceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"version"] forKey:@"version"];
    [replaceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"faultid"] forKey:@"id"];
    [replaceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"is_version"] forKey:@"is_version"];
    [tabelView reloadData];
    
}

#pragma mark 构建界面
- (void)viewFound{
    
    // 标题
    RZCustomLable *titleLabel = [[RZCustomLable alloc] initWithFrame:CGRectMake(0, 0, 80, 44)];
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.text = [UtilCheck language:@"main.creatingOrders"];
    titleLabel.backgroundColor = [UIColor clearColor];

    self.navigationItem.titleView = titleLabel;
    self.view.backgroundColor = [UtilCheck hexStringToColor:@"f1f8fd" alpha:1];
    selectedIndex = 0;
    
    // 标题
    if (self.dict != nil) {
        titleLabel.text = [UtilCheck language:@"main.orderUpdate"];
    }else {
        titleLabel.text = [UtilCheck language:@"main.creatingOrders"];
    }

    
    tabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.view.bounds.size.height - 110) style:(UITableViewStyleGrouped)];
    tabelView.backgroundColor = [UtilCheck hexStringToColor:@"f4f8fb" alpha:1];
    tabelView.delegate = self;
    tabelView.dataSource = self;
    tabelView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, tabelView.bounds.size.width, 0.01f)];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderFirstCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderFirstCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderUseRepairsCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderUseRepairsCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderMessageCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderMessageCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderReplaceCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderReplaceCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderLogisticsCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderLogisticsCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderDeliveryCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderDeliveryCell"];
    
    tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:tabelView];
    // 标题
    if (self.order == 0) {
        self.labnav.text= [UtilCheck language:@"main.creatingOrders"];
    }else if (self.order == 1){
        self.labnav.text= [UtilCheck language:@"main.orderUpdate"];
    }
    // 修改订单头
    if (self.order == 1) {
        tabelView.tableHeaderView = ({
            UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tabelView.frame.size.width, 60)];
            header.backgroundColor = [UtilCheck hexStringToColor:@"1a56bc" alpha:1];
            
            RZCustomLable *orderIDLabel = [[RZCustomLable alloc]initWithFrame:CGRectMake(5, 5, 200, 20)];
            orderIDLabel.text = [NSString stringWithFormat:@"订单号:%@",self.dict[@"orderStatus"][@"orderCode"]];
            orderIDLabel.textColor = [UIColor whiteColor];
            orderIDLabel.font = [UIFont systemFontOfSize:12];
            [header addSubview:orderIDLabel];
            RZCustomLable *ordersTiemLabel = [[RZCustomLable alloc]initWithFrame:CGRectMake(5, 25, 200, 20)];
            ordersTiemLabel.text = [NSString stringWithFormat:@"下单时间:%@",self.dict[@"orderStatus"][@"orderTime"]];
            ordersTiemLabel.textColor = [UIColor whiteColor];
            ordersTiemLabel.font = [UIFont systemFontOfSize:12];
            [header addSubview:ordersTiemLabel];
            RZCustomLable *service_timeLabel = [[RZCustomLable alloc]initWithFrame:CGRectMake(5, 45, 200, 20)];
            service_timeLabel.text = [NSString stringWithFormat:@"下单时间:%@",self.dict[@"orderStatus"][@"service_time"]];
            service_timeLabel.textColor = [UIColor whiteColor];
            service_timeLabel.font = [UIFont systemFontOfSize:12];
            [header addSubview:service_timeLabel];
            RZCustomLable *stateLabel = [[RZCustomLable alloc]initWithFrame:CGRectMake(tabelView.bounds.size.width - 70, 5, 40, 40)];
            stateLabel.backgroundColor = [UtilCheck hexStringToColor:@"ff9c5a" alpha:1];
            stateLabel.text = self.dict[@"orderStatus"][@"statusName"];
            stateLabel.textColor = [UIColor whiteColor];
            stateLabel.font = [UIFont systemFontOfSize:13];
            stateLabel.textAlignment = NSTextAlignmentCenter;
            stateLabel.layer.cornerRadius = 20;
            
            stateLabel.layer.masksToBounds = YES;
            
            
            [header addSubview:stateLabel];
            
            header;
        });
    }
    
    //提交
    RZCustomButtom *commit = [[RZCustomButtom alloc]init];
    commit.frame = CGRectMake((tabelView.bounds.size.width - (tabelView.bounds.size.width - 30)) / 2,self.view.bounds.size.height - 108,tabelView.bounds.size.width - 30,40);
    [commit setBackgroundImage:BDFILEIMAGENAEM(@"Order/btn_submit.png") forState:(UIControlStateNormal)];
    [commit setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [commit setTitle:[UtilCheck language:@"main.submitOrder"] forState:(UIControlStateNormal)];
    [commit addTarget:self action:@selector(commitGoto) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:commit];
}
- (void)RightButton
{
    NSLog(@"?");
    ConsigneeListVC *vc = [[ConsigneeListVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark  数据初始化
- (void)dataConfig{
    
    replaceReceiptArray = [[NSMutableArray alloc]init];
    customerServiceDic = [[NSMutableDictionary alloc]init];
    replaceLogisticsDic = [[NSMutableDictionary alloc]init];

    replaceReceiptArray = [[NSMutableArray alloc]initWithObjects:[UtilCheck language:@"order.receive.address"],[UtilCheck language:@"order.customer.contacts"],[UtilCheck language:@"order.is.urgent"], nil];//,[UtilCheck language:@"order.wish.arrive.time"]
    replaceDataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"address",@"",@"tel",@"",@"user",[UtilCheck language:@"order.no"],@"isUrgent",@"",@"arriveTime", nil];
    customerServiceDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"customerID",@"",@"customerTime", nil];
    replaceFaultDataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"rma",@"",@"id",@"",@"name",@"",@"code",@"1",@"number",@"",@"describe",nil,@"image",@"",@"is_version", nil];
    replaceLogisticsDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"courierID",@"",@"courierNum",@"",@"courierName", nil];
    message = @"";
    replaceArray = [[NSMutableArray alloc]init];
    
    NSUserDefaults *userDefaultes = [NSUserDefaults standardUserDefaults];
    NSMutableArray *arr = [[NSMutableArray alloc]initWithArray:[userDefaultes arrayForKey:@"getSearcHistoryKey"]];
    if (arr.count != 0) {
        [replaceFaultDataDic setObject:arr[0] forKey:@"name"];
        [customerServiceDic setObject:arr[1] forKey:@"customerID"];
    }
    //修改不执行
    if (self.order == 1){
    }else {
        [replaceArray addObject:replaceFaultDataDic];
    }

}
#pragma mark TableViewDataSource  TableViewDelegate
// 四个组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (selectedIndex == 0) {
        return 4;
    }else if (selectedIndex == 1){
        return 4;
    }
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
        if (indexPath.section == 3) {
            return 60;
        }else if (indexPath.section == 1) {
            if (self.dict != nil) {
                return 176;
            }else {
                return 250;
            }
        }else if (indexPath.section == 2) {
            return 118;
        }else {
            return 44;
        }
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

        if (section == 0) {
            return replaceReceiptArray.count;
        }else if (section == 1) {
            if (self.order == 1) {
                NSArray *arr = self.dict[@"parts"][@"faultParts"];
                return arr.count;
            } else {
                return replaceArray.count;
            }
        }else if (section == 2){
            return 1;
        }else if (section == 3){
            return 1;
        }
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
            NSInteger section = indexPath.section;
        if (section == 0) {
            CSNewOrderCell * ordercell = [tableView dequeueReusableCellWithIdentifier:@"CSNewOrderCell" forIndexPath:indexPath];
            ordercell.selectionStyle = UITableViewCellSelectionStyleNone;
            ordercell.nemeLabel.text = replaceReceiptArray[indexPath.row];
            
            if ([ordercell.nemeLabel.text isEqualToString:[UtilCheck language:@"order.is.urgent"]]) {
                ordercell.requiredLabel.hidden = YES;
            }
            if (self.dict != nil) {
                
                ordercell.messageLabel.userInteractionEnabled = NO;
            }else {
                
                ordercell.messageLabel.userInteractionEnabled = YES;
            }
            UITapGestureRecognizer *Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
            [ordercell.messageLabel addGestureRecognizer:Recognizer];
            Recognizer.view.tag = 101 + indexPath.row;
            if (indexPath.row == 3) {
                ordercell.requiredLabel.text = @" ";
            }
            if (indexPath.row == 0) {
                ordercell.messageLabel.text = replaceDataDic[@"address"];
            }else if (indexPath.row == 1){
                ordercell.messageLabel.text = replaceDataDic[@"tel"];
            }else if (indexPath.row == 2){
                ordercell.messageLabel.text = replaceDataDic[@"isUrgent"];
            }
//            else if (indexPath.row == 3){
//                ordercell.messageLabel.text = replaceDataDic[@"arriveTime"];
//            }
            ordercell.arrowImageView.hidden = NO;
            ordercell.arrowImageView.image = BDFILEIMAGENAEM(@"UserCenter/arrow.png");
            
            ordercell.lineLabel = [[UILabel alloc]init];
            [ordercell.lineLabel setFrame:CGRectMake(0, 43.5, tabelView.width, 0.5)];
            [ordercell.lineLabel setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [ordercell addSubview:ordercell.lineLabel];
            if (indexPath.row == 0) {
                RZCustomLable *myLable = [[RZCustomLable alloc]init];
                [myLable setFrame:CGRectMake(0, 0, tabelView.width, 0.5)];
                [myLable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
                [ordercell addSubview:myLable];
            }
            return ordercell;
            
        }else if (section == 1){
            CSNewOrderReplaceCell * replacecell = [tableView dequeueReusableCellWithIdentifier:@"CSNewOrderReplaceCell" forIndexPath:indexPath];
            NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithDictionary:replaceArray[indexPath.row]];
            
            if (self.dict != nil) {
                replacecell.numberTextField.hidden = YES;
                replacecell.quantityLabel.hidden = YES;
                replacecell.coilLabel.hidden = YES;
                replacecell.thirdAsteriskLabel.hidden = YES;
                replacecell.deleteButton.hidden = YES;
                
                [replacecell.numberTextField setHeight:0.1];
                [replacecell.quantityLabel setHeight:0.1];
                [replacecell.coilLabel setHeight:0.1];
                
                replacecell.thirdCoilToSecondCoil.constant = 0.1;
                
            }else {
                if (indexPath.row == 0) {
                    replacecell.deleteButton.hidden = YES;
                }else {
                    replacecell.deleteButton.hidden = NO;
                }
            }

            replacecell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            replacecell.arrowImageView.image = BDFILEIMAGENAEM(@"UserCenter/arrow.png");
            replacecell.pickImgImageView.image = BDFILEIMAGENAEM(@"Order/img_pickImg.png");
            replacecell.arrowImageView.userInteractionEnabled = YES;
            UITapGestureRecognizer *Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
            [replacecell.nameTextField addGestureRecognizer:Recognizer];
            Recognizer.view.tag = 201 + indexPath.row;
            UITapGestureRecognizer *codeRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
            replacecell.codeTextField.userInteractionEnabled = YES;
            
            [replacecell.codeTextField addGestureRecognizer:codeRecognizer];
            codeRecognizer.view.tag = 201 + indexPath.row;
            
            replacecell.messageLabel.text = [NSString stringWithFormat:@"%@(%ld)",[UtilCheck language:@"order.faultpart.info"],indexPath.row +1];
            replacecell.deleteButton.tag = section * 1000 + indexPath.row * 100;
            [replacecell.deleteButton setTitle:[UtilCheck language:@"order.delete"] forState:UIControlStateNormal];
            [replacecell.deleteButton addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
            
            replacecell.codeTextField.tag = section * 1000 + indexPath.row * 100 + 1;
            replacecell.numberTextField.tag = section * 1000 + indexPath.row * 100 + 2;
            replacecell.nameTextField.tag = section * 1000 +indexPath.row * 100 + 3;
            replacecell.versionTextField.tag = section * 1000 +indexPath.row * 100 + 4;

            replacecell.nameTextField.text = [dic objectForKey:@"name"];
            replacecell.codeTextField.text = [dic objectForKey:@"code"];
            replacecell.versionTextField.text = [dic objectForKey:@"version"];
            replacecell.numberTextField.text = [dic objectForKey:@"number"];
            if (replaceArray[indexPath.row][@"image"] != nil) {
                    
                replacecell.pickImgImageView.image = [UIImage imageWithData:replaceArray[indexPath.row][@"image"]];
            }
            
            
            replacecell.nameTextField.placeholder = [UtilCheck language:@"order.choice.or.input"];
            
            replacecell.nameTextField.delegate = self;
            replacecell.codeTextField.delegate = self;
            replacecell.versionTextField.delegate = self;
            replacecell.numberTextField.delegate = self;
            replacecell.numberTextField.keyboardType = UIKeyboardTypePhonePad;
            
            replacecell.pickImgImageView.userInteractionEnabled = YES;
            
            UITapGestureRecognizer *imageRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
            [replacecell.pickImgImageView addGestureRecognizer:imageRecognizer];
            imageRecognizer.view.tag = 301 + indexPath.row;
            
            replacecell.nameLabel.text = [UtilCheck language:@"order.faultpart.name"];
            replacecell.codeLabel.text = [UtilCheck language:@"order.faultpart.code"];
            replacecell.quantityLabel.text = [UtilCheck language:@"order.quantity"];
            replacecell.describeLabel.text = [UtilCheck language:@"order.fault.describe"];
            replacecell.pictureLabel.text = [UtilCheck language:@"order.submit.picture"];
            
            [replacecell.describeLabel sizeToFit];
            
            
            // 分割线设置
            for (int i = 0; i < 5; i++) {
                RZCustomLable *lable = [[RZCustomLable alloc]init];
                [lable setFrame:CGRectMake(0, 44 * i - 0.5 , tabelView.width, 0.5)];
                [lable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
                [replacecell.myView addSubview:lable];
            }
            
            
            return replacecell;
        }else if (section == 2){
            CSNewOrderLogisticsCell * ordercell = [tableView dequeueReusableCellWithIdentifier:@"CSNewOrderLogisticsCell" forIndexPath:indexPath];
            ordercell.selectionStyle = UITableViewCellSelectionStyleNone;

            ordercell.courierLabel.userInteractionEnabled = YES;
            ordercell.courierLabel.text = replaceLogisticsDic[@"courierName"];
            UITapGestureRecognizer *Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
            [ordercell.courierLabel addGestureRecognizer:Recognizer];
            Recognizer.view.tag = 401 + indexPath.row;
            
            
            ordercell.courierNumTextField.delegate = self;
            ordercell.courierNumTextField.tag = section * 1000;
            ordercell.courierNumTextField.text = replaceLogisticsDic[@"courierNum"];
            
            ordercell.arrowImageView.image = BDFILEIMAGENAEM(@"UserCenter/arrow.png");
            
            ordercell.companyLabel.text = [UtilCheck language:@"order.logistics.company"];
            ordercell.NOLabel.text = [UtilCheck language:@"order.logistics.NO."];
            
            // 分割线设置
            for (int i = 0; i < 3; i++) {
                RZCustomLable *lable = [[RZCustomLable alloc]init];
                [lable setFrame:CGRectMake(0, 44 * i - 0.5 + 30 , tabelView.width, 0.5)];
                [lable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
                [ordercell addSubview:lable];
            }
            
            
            return ordercell;
        }else if (section == 3){
            CSNewOrderMessageCell * ordercell = [tableView dequeueReusableCellWithIdentifier:@"CSNewOrderMessageCell" forIndexPath:indexPath];
            ordercell.selectionStyle = UITableViewCellSelectionStyleNone;
            ordercell.messageTextView.tag = section * 1000;
            ordercell.messageTextView.text = message;

            ordercell.messageTextView.delegate = self;
            ordercell.nameLabel.text = [UtilCheck language:@"order.remark"];
            
            RZCustomLable *lable = [[RZCustomLable alloc]init];
            [lable setFrame:CGRectMake(0, 0, tabelView.width, 0.5)];
            [lable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [ordercell addSubview:lable];
            RZCustomLable *linLable = [[RZCustomLable alloc]init];
            [linLable setFrame:CGRectMake(0, 59.5, tabelView.width, 0.5)];
            [linLable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [ordercell addSubview:linLable];
            
            return ordercell;
        }
    return nil;
    
}

#pragma mark 表头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tabelView.bounds.size.width, 30)];
        headerView.backgroundColor = [UtilCheck hexStringToColor:@"f5f7fa" alpha:1];
        
        RZCustomLable *receiptInfo = [[RZCustomLable alloc]initWithFrame:CGRectMake(8, 5, 200, 20)];
        receiptInfo.text = [NSString stringWithFormat:@"%@",[UtilCheck language:@"order.receive.info"]];
        receiptInfo.textColor = [UtilCheck hexStringToColor:@"858e99" alpha:1];
        receiptInfo.font = [UIFont systemFontOfSize:11.5];
        [headerView addSubview:receiptInfo];
        
        RZCustomButtom *rightButton = [RZCustomButtom buttonWithType:UIButtonTypeCustom];
        [rightButton setTitle:[UtilCheck language:@"setting.addConsignee"] forState:UIControlStateNormal];
        [rightButton setTitleColor:[UtilCheck hexStringToColor:@"0056b8" alpha:1] forState:UIControlStateNormal];
        rightButton.frame = CGRectMake(headerView.bounds.size.width - 110, 0, 100, 30);
        rightButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [rightButton addTarget:self action:@selector(RightButton) forControlEvents:UIControlEventTouchUpInside];
        [headerView addSubview:rightButton];
        
        return headerView;

    }else if (section == 2){
        
            if (self.dict != nil) {
                
            }else {
                UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tabelView.bounds.size.width, 50)];
                header.backgroundColor = [UIColor whiteColor];
                
                RZCustomLable *linLable = [[RZCustomLable alloc]init];
                [linLable setFrame:CGRectMake(0, header.height, tabelView.width, 0.5)];
                [linLable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
                [header addSubview:linLable];

                RZCustomButtom *append = [[RZCustomButtom alloc]init];
                append.frame = CGRectMake((tabelView.bounds.size.width - 150) / 2,10,150,30);
                [append setImage:BDFILEIMAGENAEM(@"Order/btn_add.png") forState:UIControlStateNormal];
                [append setTitle:[NSString stringWithFormat:@"  %@",[UtilCheck language:@"order.add.faultpart.info"]] forState:UIControlStateNormal];
                append.titleLabel.font = [UIFont systemFontOfSize:14];

                [append setTitleColor:[UtilCheck hexStringToColor:@"6990f3" alpha:1] forState:UIControlStateNormal];
                [append addTarget:self action:@selector(additionMessage) forControlEvents:UIControlEventTouchUpInside];
                [header addSubview:append];
                
                RZCustomButtom *sweepButton = [[RZCustomButtom alloc]initWithFrame:CGRectMake(header.bounds.size.width - 55, 10, 40, 40)];
                sweepButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentCenter;
                [sweepButton setImage:BDFILEIMAGENAEM(@"Order/scan.png") forState:UIControlStateNormal];
                sweepButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 10, 0);
                sweepButton.titleLabel.font = [UIFont systemFontOfSize:10];
                [sweepButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
                sweepButton.titleEdgeInsets = UIEdgeInsetsMake(30, -20, 0, 0);
                [sweepButton addTarget:self action:@selector(sweepButton) forControlEvents:UIControlEventTouchUpInside];
                
                [header addSubview:sweepButton];

                return header;
            }
    }
    
    return nil;
}

- (void)sweepButton {
    
    MHScanViewController *MHsvc = [[MHScanViewController alloc]init];
    MHsvc.isdismiss = YES;
    
    MHsvc.rebackData = ^(NSString *retStr){
        
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        
        params[@"code"] = retStr;
        
        params[@"orderType"] = @"2";
        
        [[BDHUD sharedManager] showBDHUD:self.view title:nil];
        [AFHttpTool postJsonDatawithUrl:@"scanAddFailureparts" parameters:[params mutableCopy] success:^(id responseObject) {
            [[BDHUD sharedManager] dismissHUD];
            
            NSArray *arr = responseObject[@"data"];
            
            if (arr.count != 0) {
                NSDictionary *dic = arr[0];
                
                NSLog(@"%@",dic);
                
                NSDictionary *DataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"id",dic[@"name"],@"name",dic[@"code"],@"code",dic[@"version"],@"version",@"1",@"number",@"",@"describe",nil,@"image",dic[@"faultPartType"],@"faultPartType", nil];
                
                NSLog(@"%@",DataDic);

                [replaceArray addObject:DataDic];
                [tabelView reloadData];
                
            }else {
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.did.not.find.the.related.plate"]];
            }
            
        } fail:^(id responseObject, NSError *error) {
            [[BDHUD sharedManager] dismissHUD];
            
            [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.title.the.data.load.failure"]];
        }];
    };
    
    CustomNavigationController *vc = [[CustomNavigationController alloc]initWithRootViewController:MHsvc];
    
    [self presentViewController:vc animated:YES completion:^{
        
    }];
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 30;
    }else if (section == 1){
        return 0.01;
    }else if (section == 2){
        if (self.dict != nil) {
            return 0.01;
        }else {
            return 50;
        }
    }else if (section == 3){
        return 10;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

// 点击获取收货信息数据
#pragma mark 获取数据
- (void)acquireData:(UITapGestureRecognizer *)tgr
{
    NSLog(@"点击的tag== %ld",tgr.view.tag);
    
            if (tgr.view.tag == 101) {   //选择收货地址
            [[BDHUD sharedManager] showBDHUD:self.view title:nil];

            [AFHttpTool postJsonDatawithUrl:@"getAddresses" parameters:nil success:^(id responseObject) {
                [[BDHUD sharedManager] dismissHUD];

                if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
                    NSArray *array = [responseObject objectForKey:@"data"];
                    NSLog(@"地址为%@",array);
                    NSMutableArray *actionArray = [[NSMutableArray alloc]init];
                    for (int i = 0; i < array.count; i++) {
                        [actionArray addObject:array[i][@"address"]];
                    }
                    PXAlertView *AlertView = [[PXAlertView alloc]initAlertWithTitle:[UtilCheck language:@"order.receive.address"] message:nil cancelTitle:nil otherTitle:nil contentView:nil completion:nil tableview:actionArray];
                    AlertView.delegate = self;
                    AlertView.mark = tgr.view.tag;
                    [AlertView show];
                }else {
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                
            } fail:^(id responseObject, NSError *error) {
                
                [[BDHUD sharedManager] dismissHUD];
                
                if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
                }else {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
                }
            }];
        }else if (tgr.view.tag == 102){    //选择客户
            [[BDHUD sharedManager] showBDHUD:self.view title:nil];

            [AFHttpTool postJsonDatawithUrl:@"myConsignees" parameters:nil success:^(id responseObject) {
                [[BDHUD sharedManager] dismissHUD];

                if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
                    myConsigneesArray = [responseObject objectForKey:@"data"];
                    NSLog(@"地址为%@",myConsigneesArray);
                    
                    NSMutableArray *actionArray = [[NSMutableArray alloc]init];
                    for (NSDictionary *dic in myConsigneesArray) {
                        [actionArray addObject:[NSString stringWithFormat:@"%@ %@",dic[@"username"],dic[@"tel"]]];
                    }
                    PXAlertView *AlertView = [[PXAlertView alloc]initAlertWithTitle:[UtilCheck language:@"order.customer.contacts"] message:nil cancelTitle:nil otherTitle:nil contentView:nil completion:nil tableview:actionArray];
                    AlertView.delegate = self;
                    AlertView.mark = tgr.view.tag;
                    [AlertView show];
                }else {
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                
            } fail:^(id responseObject, NSError *error) {
                
                [[BDHUD sharedManager] dismissHUD];
                
                if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
                }else {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
                }
            }];
            
        }else if (tgr.view.tag == 103){   //是否加急
            alertView = [UIAlertController alertControllerWithTitle:[UtilCheck language:@"order.is.urgent"] message:nil preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *rightAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"order.yes"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [replaceDataDic setValue:[UtilCheck language:@"order.yes"] forKey:@"isUrgent"];
                
                // 背景色
                shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
                shadowView.backgroundColor = [UtilCheck hexStringToColor:@"a5a9aa" alpha:0.7];
                // 确认提交界面
                [self.view addSubview:shadowView];
                UIView *submitView;
                
                submitView = [[UIView alloc]initWithFrame:CGRectMake((shadowView.bounds.size.width - 250) / 2, 70, 250, 200)];

                submitView.layer.cornerRadius = 5;
                submitView.layer.masksToBounds = YES;
                submitView.backgroundColor = [UIColor whiteColor];;
                [shadowView addSubview:submitView];
                
                //头部
                UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, submitView.bounds.size.width, 70)];
                headView.backgroundColor = [UtilCheck hexStringToColor:@"9ed4e2" alpha:1];
                [submitView addSubview:headView];
                UIImageView *headImageView = [[UIImageView alloc]initWithFrame:CGRectMake((headView.bounds.size.width - 60) / 2, 5, 60, 60)];
                headImageView.image = BDFILEIMAGENAEM(@"Order/img_pack.png");
                [headView addSubview:headImageView];
                
                UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake((submitView.bounds.size.width - 100) / 2, headView.bounds.size.height + 10, 100, 20)];
                lineLabel.text = @"加急提醒";
                lineLabel.textColor = [UtilCheck hexStringToColor:@"626364" alpha:1];
                lineLabel.textAlignment = NSTextAlignmentCenter;
                lineLabel.font = [UIFont systemFontOfSize:15];
                [submitView addSubview:lineLabel];
                
                UILabel *remindLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, headView.bounds.size.height + 10 +lineLabel.bounds.size.height + 10, 200, 45)];
                remindLabel.text = @"请与您的专属客服确认库存信息，谢谢！";
                remindLabel.numberOfLines = 0;
                remindLabel.textColor = [UtilCheck hexStringToColor:@"929293" alpha:1];
                remindLabel.textAlignment = NSTextAlignmentCenter;
                remindLabel.font = [UIFont systemFontOfSize:15];
                [submitView addSubview:remindLabel];
                
                UIButton *modifyButton = [UIButton buttonWithType:UIButtonTypeCustom];
                modifyButton.frame = CGRectMake((submitView.bounds.size.width - 100) / 2, (submitView.bounds.size.height - 30), 100, 20);
                [modifyButton setTitle:@"我知道了" forState:UIControlStateNormal];
                [modifyButton setTitleColor:[UtilCheck hexStringToColor:@"12a9d1" alpha:1] forState:UIControlStateNormal];
                [modifyButton addTarget:self action:@selector(modify) forControlEvents:UIControlEventTouchUpInside];
                
                [submitView addSubview:modifyButton];
                
                
                [tabelView reloadData];
            }];
            UIAlertAction *denyAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"order.no"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [replaceDataDic setValue:[UtilCheck language:@"order.no"] forKey:@"isUrgent"];
                
                [tabelView reloadData];
            }];
            [alertView addAction:rightAction];
            [alertView addAction:denyAction];
            [self presentViewController:alertView animated:YES completion:nil];
        }else if (tgr.view.tag == 104) {
            UIView *maskView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tabelView.bounds.size.width, self.view.height*2)];
            maskView.backgroundColor = [UIColor whiteColor];
            maskView.alpha = 0.2f;
            self.maskView = maskView;
            [tabelView addSubview:self.maskView];
            
            //设置选择时间的TextField
            datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 216, self.view.frame.size.width, 216)];
            datePicker.backgroundColor = [UIColor whiteColor];
            datePicker.datePickerMode = UIDatePickerModeDateAndTime;
            datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CH"];
            
            toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 216 - 44, self.view.frame.size.width, 44.0f)];
            toolBar.backgroundColor = [UIColor grayColor];
            UIBarButtonItem* leftItem = [[UIBarButtonItem alloc] initWithTitle:[UtilCheck language:@"button.cancel"] style:UIBarButtonItemStyleDone target:self action:@selector(cancelAction)];
            UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
            UIBarButtonItem* rightItem = [[UIBarButtonItem alloc] initWithTitle:[UtilCheck language:@"button.done"] style:UIBarButtonItemStyleDone target:self action:@selector(confirmAction)];
            rightItem.tag = tgr.view.tag;
            [toolBar setItems:@[leftItem,flexSpace,rightItem]];
            [self.view addSubview:datePicker];
            [self.view addSubview:toolBar];
        }else if (tgr.view.tag == 401){    //选择物流公司
            [[BDHUD sharedManager] showBDHUD:self.view title:nil];

            [AFHttpTool postJsonDatawithUrl:@"getLogisticsCompany" parameters:nil success:^(id responseObject) {
                [[BDHUD sharedManager] dismissHUD];

                if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
                    logisticsArray = [responseObject objectForKey:@"data"];
                    NSLog(@"地址为%@",logisticsArray);
                    
                    NSMutableArray *actionArray = [[NSMutableArray alloc]init];
                    for (NSDictionary *dic in logisticsArray) {
                        [actionArray addObject:dic[@"name"]];
                    }
                    PXAlertView *AlertView = [[PXAlertView alloc]initAlertWithTitle:[UtilCheck language:@"order.logistics.company"] message:nil cancelTitle:nil otherTitle:nil contentView:nil completion:nil tableview:actionArray];
                    AlertView.delegate = self;
                    AlertView.mark = tgr.view.tag;
                    [AlertView show];
                }else {
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                
            } fail:^(id responseObject, NSError *error) {
                
                [[BDHUD sharedManager] dismissHUD];
                
                if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
                }else {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
                }
            }];
            
        }else if ((tgr.view.tag % 10 == 3 || tgr.view.tag % 10 == 1 )&& tgr.view.tag > 1000 ){
            CNewOrderFaultyPartsVC *vc = [[CNewOrderFaultyPartsVC alloc]init];
            vc.tag = [NSString stringWithFormat:@"%ld",tgr.view.tag];
            vc.selectedIndex = 1;
            vc.judge = PartDefault;
            vc.orderType = @"2";
            if (self.dict != nil) {
                vc.fualtPartType = replaceArray[tgr.view.tag / 100 - 10][@"faultPartType"];
            }
            [self.navigationController pushViewController:vc animated:YES];
        }else if (tgr.view.tag / 100 ==3){
            UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:[UtilCheck language:@"title.title"] delegate:self cancelButtonTitle:[UtilCheck language:@"title.cancel"] destructiveButtonTitle:[UtilCheck language:@"title.takePhotos"] otherButtonTitles:[UtilCheck language:@"title.photoAlbum"],[UtilCheck language:@"title.delete"],[UtilCheck language:@"title.largerImage"], nil];
            actionSheet.tag = tgr.view.tag;
            actionSheet.delegate=self;
            [actionSheet showInView:self.view];
        }
}
- (void)cancelAction {
    [self.maskView removeFromSuperview];
    
    [datePicker removeFromSuperview];
    [toolBar removeFromSuperview];
}
- (void)confirmAction {
    [self.maskView removeFromSuperview];
    
    [datePicker removeFromSuperview];
    [toolBar removeFromSuperview];
    
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm";
    
    //选择时间不能大于当前时间
    NSDate *selectedDate = datePicker.date;
    NSDate *nowDate = [NSDate date];
    
    if ([selectedDate earlierDate:nowDate] == selectedDate ) {
        [Toolobject showTextWithMessage:[UtilCheck language:@"datePicker.noBeforeNow"]];
        return;
    }
    NSString *dateStr = [formatter stringFromDate:datePicker.date];
    [replaceDataDic setValue:dateStr forKey:@"arriveTime"];
    [tabelView reloadData];

}
#pragma mark 获取图片
- (void)setUpImageArray{
    
    NSLog(@"带有图片地址的数据%@",replaceArray);
    which = 0;
    for (NSDictionary *dictionar in replaceArray) {
        NSString *currentPicAddress = [dictionar objectForKey:@"describe"];
        
        if (currentPicAddress != nil ) {
            NSDictionary *diction = @{@"filePath":currentPicAddress};
            
//            [[BDHUD sharedManager] showBDHUD:self.view title:nil];
            [[BDHUD sharedManager] showBDUploadHUD:self.view title:[THMangerTool language:@"MJ.loadingMore"]];
            [AFHttpTool postJsonDatawithUrl:@"getOrderFile"  parameters:diction success:^(id responseObject) {
                NSLog(@"%@",responseObject);
                
                [[BDHUD sharedManager] dismissHUD];
                
            } fail:^(id responseObject, NSError *error) {
                [[BDHUD sharedManager] dismissHUD];
                
                NSData *data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                NSFileManager *fileManager = [NSFileManager defaultManager];
                
                //判断MyImageFolder文件夹是否存在
                BOOL fileExists = [fileManager fileExistsAtPath:UPLOAD(@"")];
                if(!fileExists)
                {
                    [fileManager createDirectoryAtPath:UPLOAD(@"") withIntermediateDirectories:YES attributes:nil error:nil];
                }
                
                NSString *fileOldPath=[NSString stringWithFormat:@"%@/DT_%@.jpg",UPLOAD(@""),[UtilCheck DateToTimestamp]];
                
                [data writeToFile:fileOldPath atomically:NO]; //写入文件
                [replaceArray[which] setValue:data forKey:@"image"];
                which++;
            }];
            
        }
        
    }
    NSLog(@"%@",replaceArray);
    
}

#pragma mark -选择照片
- (BOOL)isCameraAvailable{
    
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    UIImagePickerController *controller = [[UIImagePickerController alloc] init];
    controller.view.tag = actionSheet.tag;
    [controller setAllowsEditing:NO];
    controller.delegate=self;
    
    NSLog(@"tag== %ld",controller.view.tag);
    
    if (buttonIndex==0) {
        if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:[UtilCheck language:@"title.takePhotos"]]){
            // 判断有摄像头，并且支持拍照功能
            if ([self isCameraAvailable] )
            {
                // 初始化图片选择控制器
                [controller setSourceType:UIImagePickerControllerSourceTypeCamera];// 设置类型
                [self presentViewController:controller animated:YES completion:Nil];
            }else{
                UIAlertView *message = [[UIAlertView alloc]initWithTitle:[UtilCheck language:@"title.title"] message:@"该设备不支持拍照功能" delegate:nil cancelButtonTitle:[UtilCheck language:@"button.done"] otherButtonTitles:nil];
                [message show];
            }
        }
    }else if (buttonIndex==1){
        if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:[UtilCheck language:@"title.photoAlbum"]]){
            //从相册选取
            [controller setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];// 设置类型
            [self presentViewController:controller animated:YES completion:Nil];
        }
    }else{
        if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:[UtilCheck language:@"title.delete"]]){
            if (replaceArray[actionSheet.tag % 10 - 1][@"image"] != nil) {
                replaceArray[actionSheet.tag % 10 - 1][@"image"] = nil;
                [tabelView reloadData];
                
            }else {
                [Toolobject showAlterwithMessage:[UtilCheck language:@"setting.emptyPhoto"]];
            }
            
        }else  if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:[UtilCheck language:@"title.largerImage"]]){
            
            NSData *imgData =replaceArray[actionSheet.tag % 10 - 1][@"image"];
            
            if (imgData != nil) {
                
                UIImage *img = [UIImage imageWithData:imgData];
                guzhangphoto = [MWPhoto photoWithImage:img] ;
                
                MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
                
                browser.displayActionButton = NO;//分享按钮,默认是
                browser.displayNavArrows = NO;//左右分页切换,默认否
                browser.displaySelectionButtons = NO;//是否显示选择按钮在图片上,默认否
                browser.alwaysShowControls = NO;//底部 顶部控制条件控件 是否显示,默认否
                browser.zoomPhotosToFill = YES;//是否全屏,默认是
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
                browser.wantsFullScreenLayout = YES;//是否全屏
#endif
                browser.enableGrid = NO;//是否允许用网格查看所有图片,默认是
                browser.startOnGrid = YES;//是否第一张,默认否
                browser.enableSwipeToDismiss = YES;
                
                [browser setCurrentPhotoIndex:0];
                
                CustomNavigationController *navCon = [[CustomNavigationController alloc] initWithRootViewController:browser];
                
                [self presentViewController:navCon animated:YES completion:nil];
                
            }else{
                
                [Toolobject showAlterwithMessage:@"暂无图片"];
            }
        }
    }
    
}

#pragma mark - MWPhotoBrowser协议
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    
    return  1;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    
    return guzhangphoto;
}


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    
    UIImage* theImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSData *imageDate = UIImagePNGRepresentation(theImage);
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    //判断MyImageFolder文件夹是否存在
    BOOL fileExists = [fileManager fileExistsAtPath:UPLOAD(@"")];
    if(!fileExists)
    {
        [fileManager createDirectoryAtPath:UPLOAD(@"") withIntermediateDirectories:YES attributes:nil error:nil];
    }
    
    NSString *filePath=[NSString stringWithFormat:@"%@/DT_%@.jpg",UPLOAD(@""),[UtilCheck DateToTimestamp]];
    
    [imageDate writeToFile:filePath atomically:NO]; //写入文件
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    [array addObject:filePath];
    
//    [[BDHUD sharedManager] showBDUploadHUD:self.view title:@"正在上传文件..."];
    [[BDHUD sharedManager] showWords:[THMangerTool language:@"setting.upload.a.file"]];
    [AFHttpTool postFilewithUrl:@"submitOderFile" parameters:nil file:array success:^(id responseObject) {
        [[BDHUD sharedManager] dismissHUD];

        NSLog(@" 选择图片返回信息 %@",responseObject);
        if ([[[responseObject objectForKey:@"head"]objectForKey:@"status"] intValue] == 1) {
            NSString *urlImage = [[responseObject objectForKey:@"data"]objectForKey:@"url"];
            [replaceArray[picker.view.tag % 100 - 1] setValue:urlImage forKey:@"describe"];
            [replaceArray[picker.view.tag % 100 - 1] setValue:imageDate forKey:@"image"];
            [self dismissViewControllerAnimated:YES completion:^{
                [tabelView reloadData];
            }];
        }
        
    } progress:^(NSProgress *uploadProgress) {
        [[BDHUD sharedManager] dismissHUD];

        NSLog(@"+++++++++++%@",uploadProgress);
        
    } fail:^(id responseObject, NSError *error) {
        [[BDHUD sharedManager] dismissHUD];

        NSLog(@"!!!!!!!!!!!!!!%@",error);
    }];
    
    
   
}


#pragma mark PXAlertViewDelegate 选择获取的数据放入label中
- (void)getselect:(NSString *)getselect mark:(int)mark row:(int)row
{
    NSLog(@"%@    %d    %d",getselect,mark,row);
    
        if (getselect != nil) {
            if (mark == 101) {
                [replaceDataDic setValue:getselect forKey:@"address"];
                [tabelView reloadData];
            }else if (mark == 102){
                [replaceDataDic setValue:getselect forKey:@"tel"];
                [replaceDataDic setValue:myConsigneesArray[row][@"id"] forKey:@"user"];
                
                [tabelView reloadData];
            }
            if (mark == 401) {
                NSLog(@"%@",logisticsArray);
                
                [replaceLogisticsDic setValue:getselect forKey:@"courierName"];
                [replaceLogisticsDic setValue:logisticsArray[row][@"id"] forKey:@"courierID"];
                NSLog(@"%@",replaceLogisticsDic);
                
                [tabelView reloadData];
            }
        }
}


#pragma mark 删除故障件信息
- (void)delete:(UIButton *)button
{

        
        NSLog(@"Tag== %ld",button.tag);
        NSInteger teg = button.tag / 100 - 10;
        
        [replaceArray removeObjectAtIndex:teg];
        
        [tabelView reloadData];
}
#pragma mark 保存textField数据
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    
        NSLog(@"tag==%ld",textField.tag);
        
        if (textField.tag % 10 == 2) {
            
            if ([textField.text intValue] < 10 && [textField.text intValue] > 0) {
                [replaceArray[textField.tag / 100 - 10] setValue:textField.text forKey:@"number"];

            }else {
                [replaceArray[textField.tag / 100 - 10] setValue:@"1" forKey:@"number"];
                textField.text = @"1";

                [Toolobject showAlterwithMessage:@"数量只能在1到10之间"];
            }
            
        }else if (textField.tag / 1000 == 2){
            replaceLogisticsDic[@"courierNum"] = textField.text;
        }else if (textField.tag % 10 == 4){
            [replaceArray[textField.tag / 100 - 10] setValue:textField.text forKey:@"version"];
        }
    
    return YES;
}

#pragma mark 限制字数
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSMutableString *text = [textField.text mutableCopy];
    [text replaceCharactersInRange:range withString:string];
    NSInteger limitedLength = 50;
    
    if ([text length] <= limitedLength || [string isEqualToString:@""]) {
        return YES;
    }else {
        [Toolobject showAlterwithMessage:[NSString stringWithFormat:@"最多%ld个字符",(long)limitedLength]];
        return NO;
    }
    return YES;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSMutableString *textString = [textView.text mutableCopy];
    [textString replaceCharactersInRange:range withString:text];
    NSInteger limitedLength = 200;
    
    if ([textString length] <= limitedLength || [textString isEqualToString:@""]) {
        return YES;
    }else {
        [Toolobject showAlterwithMessage:[NSString stringWithFormat:@"最多%ld个字符",(long)limitedLength]];
        return NO;
    }
    return YES;
}

- (void)textViewDidEndEditing:(UITextView *)textView{
    
        message = textView.text;
        NSLog(@"备注%@",message);
}

#pragma mark 添加故障需求信息
- (void)additionMessage
{
        NSDictionary *dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"id",@"",@"name",@"",@"code",@"1",@"number",@"",@"describe",nil,@"image", nil];
        [replaceArray addObject:dic];
        [tabelView reloadData];
    
    
    
}
#pragma mark-提交订单
- (void)commitGoto{

    NSLog(@"收货信息%@",replaceDataDic);
    // 判断是否为空
    
    if ([UtilCheck DataIsNuLL:[replaceDataDic objectForKey:@"address"]]){
        [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.receive.address empty"]];
        return;
    }else if ([UtilCheck DataIsNuLL:[replaceDataDic objectForKey:@"tel"]]){
        [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.receiver.contacts empty"]];
        return;
    }
    
    for (int i = 0; i < replaceArray.count; i++) {
        
        if ([UtilCheck DataIsNuLL:[replaceArray[i] objectForKey:@"name"]]) {
            [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.faultpart.name empty"]];
            return;
        }else {
            NSMutableArray *arr = [NSMutableArray array];
            [arr addObject:replaceArray[i][@"name"]];
            [arr addObject:customerServiceDic[@"customerID"]];
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            [userDefaults setObject:arr forKey:@"getSearcHistoryKey"];
            [userDefaults synchronize];

            
            if ([UtilCheck DataIsNuLL:[replaceArray[i] objectForKey:@"code"]]) {
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.faultpart.code empty"]];
                return;
            }else if ([UtilCheck DataIsNuLL:[replaceArray[i] objectForKey:@"number"]]) {
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"Order.FaultyUnitQty empty"]];
                return;
            }
            if ([[replaceArray[i] objectForKey:@"number"] isEqualToString:@"0"]) {
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"Order.FaultyUnitQty empty cannot be zero"]];
                return;
            }

        }
        
    }
    // 背景色
    shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    shadowView.backgroundColor = [UtilCheck hexStringToColor:@"a5a9aa" alpha:0.7];
    // 确认提交界面
    [self.view addSubview:shadowView];
    
#pragma mark 故障件信息
    NSMutableDictionary *messageDic;
    messageDic = [[NSMutableDictionary alloc]init];
    for (int i = 0; i < replaceArray.count; i++) {
        int number;
        number = 0;
        NSString *name = replaceArray[i][@"name"];
        NSString *code = replaceArray[i][@"code"];
        if (i >= 1) {
            number = 0;
            for (NSDictionary *dict in replaceArray) {
                
                if ([name isEqualToString:dict[@"name"]] && [code isEqualToString:dict[@"code"]]) {
                    number = number + [dict[@"number"]intValue];
                }
                [messageDic setObject:[NSString stringWithFormat:@"%d",number] forKey:[NSString stringWithFormat:@"%@  %@",name,code]];
            }
        }else {
            [messageDic setObject:[NSString stringWithFormat:@"%@",replaceArray[i][@"number"]] forKey:[NSString stringWithFormat:@"%@  %@",name,code]];
        }
    }
    
#pragma mark 一线备件信息
    NSMutableDictionary *lineDic;
    lineDic = [[NSMutableDictionary alloc]init];
    for (int i = 0; i < replaceArray.count; i++) {
        if ([replaceArray[i][@"isUseOneLine"] isEqualToString:[UtilCheck language:@"order.yes"]]) {
            
            int number;
            number = 0;
            NSString *name = replaceArray[i][@"oneLineName"];
            NSString *code = replaceArray[i][@"oneLineCode"];
            
            if (i >= 1) {
                number = 0;
                for (NSDictionary *dict in replaceArray) {
                    
                    if ([name isEqualToString:dict[@"oneLineName"]] && [code isEqualToString:dict[@"oneLineCode"]]) {
                        number ++;
                    }
                    [lineDic setObject:[NSString stringWithFormat:@"%d",number] forKey:[NSString stringWithFormat:@"%@  %@",name,code]];
                }
            }
            
            [lineDic setObject:[NSString stringWithFormat:@"%d",number] forKey:[NSString stringWithFormat:@"%@  %@",name,code]];
        }
        
    }
    
    NSInteger  lineTotal = 0;
    for (NSString *string in lineDic) {
        lineTotal = lineTotal + [lineDic[string] intValue];
    }
    
    [lineDic setObject:[NSString stringWithFormat:@"%ld",lineTotal] forKey:@"合计"];
    
    
    UIView *submitView;
    
    if (messageDic.count > 6) {
        submitView = [[UIView alloc]initWithFrame:CGRectMake(50, 70, self.view.bounds.size.width - 100, 70 + 40 + 100 + 55)];
        
    }else {
        if (lineDic.count > 1) {
            submitView = [[UIView alloc]initWithFrame:CGRectMake(50, 70, self.view.bounds.size.width - 100, 70 + 40 + messageDic.count * 20 + 30 + 55 + 20 * lineDic.count)];
        }else {
            submitView = [[UIView alloc]initWithFrame:CGRectMake(50, 70, self.view.bounds.size.width - 100, 70 + 40 + messageDic.count * 20 + 55)];
        }
    }
    
    submitView.layer.cornerRadius = 5;
    submitView.layer.masksToBounds = YES;
    submitView.backgroundColor = [UtilCheck hexStringToColor:@"eaebec" alpha:1];;
    [shadowView addSubview:submitView];
    
    //头部
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, submitView.bounds.size.width, 70)];
    headView.backgroundColor = [UtilCheck hexStringToColor:@"9ed4e2" alpha:1];
    [submitView addSubview:headView];
    UIImageView *headImageView = [[UIImageView alloc]initWithFrame:CGRectMake((headView.bounds.size.width - 60) / 2, 5, 60, 60)];
    headImageView.image = BDFILEIMAGENAEM(@"Order/img_pack.png");
    [headView addSubview:headImageView];
    
    if (messageDic.count <= 6) {
        UIView *defectiveView = [[UIView alloc]initWithFrame:CGRectMake(0, 70, submitView.bounds.size.width, messageDic.count * 20 + 55)];
        defectiveView.backgroundColor = [UIColor whiteColor];
        [submitView addSubview:defectiveView];
        UILabel *defectiveLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 200, 20)];
        defectiveLabel.text = [UtilCheck language:@"Order.OrderSummary"];
        defectiveLabel.font = [UIFont systemFontOfSize:15];
        [defectiveView addSubview:defectiveLabel];
        
        int j = 0;
        for (NSString *string in messageDic) {
            
            UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
            messageLabel.font = [UIFont systemFontOfSize:13];
            messageLabel.text = [NSString stringWithFormat:@"%@",string];
            [defectiveView addSubview:messageLabel];
            
            UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
            numberLabel.font = [UIFont systemFontOfSize:13];
            numberLabel.text = [NSString stringWithFormat:@"%@",messageDic[string]];
            [defectiveView addSubview:numberLabel];
            j++;
            
        }
        
        
        NSInteger  messageTotal = 0;
        for (NSDictionary *dict in replaceArray) {
            messageTotal = messageTotal + [dict[@"number"] intValue];
            
        }
        UILabel *totalNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
        totalNumberLabel.font = [UIFont systemFontOfSize:13];
        totalNumberLabel.text = [THMangerTool language:@"show.totalCount"];
        [defectiveView addSubview:totalNumberLabel];
        
        UILabel *totalLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
        totalLabel.font = [UIFont systemFontOfSize:13];
        
        totalLabel.text = [NSString stringWithFormat:@"%ld",messageTotal];
        [defectiveView addSubview:totalLabel];
        
        if (lineDic.count > 1){
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0,71 + defectiveView.bounds.size.height, submitView.bounds.size.width, lineDic.count * 20 + 30)];
            lineView.backgroundColor = [UIColor whiteColor];
            [submitView addSubview:lineView];
            
            UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 200, 20)];
            lineLabel.text = [THMangerTool language:@"newOrder.UseOnSiteSpareInfo"];
            lineLabel.font = [UIFont systemFontOfSize:15];
            [lineView addSubview:lineLabel];
            int j = 0;
            for (NSString *string in lineDic) {
                
                UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
                lineLabel.font = [UIFont systemFontOfSize:13];
                lineLabel.text = [NSString stringWithFormat:@"%@",string];
                [lineView addSubview:lineLabel];
                
                UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
                numberLabel.font = [UIFont systemFontOfSize:13];
                numberLabel.text = [NSString stringWithFormat:@"%@",lineDic[string]];
                [lineView addSubview:numberLabel];
                j++;
            }
            
        }
        
    }else {
        UIView *defectiveView = [[UIView alloc]initWithFrame:CGRectMake(0, 70, submitView.bounds.size.width, 155)];
        defectiveView.backgroundColor = [UIColor whiteColor];
        [submitView addSubview:defectiveView];
        
        UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, defectiveView.bounds.size.width, defectiveView.bounds.size.height)];
        scrollView.delegate = self;
        scrollView.backgroundColor = [UIColor whiteColor];
        scrollView.alwaysBounceVertical = YES;
        
        UILabel *defectiveLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 200, 20)];
        defectiveLabel.text = [UtilCheck language:@"Order.FaultyUnitInfo"];
        defectiveLabel.font = [UIFont systemFontOfSize:15];
        
        [scrollView addSubview:defectiveLabel];
        
        int j = 0;
        for (NSString *string in messageDic) {
            
            UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
            messageLabel.font = [UIFont systemFontOfSize:13];
            messageLabel.text = [NSString stringWithFormat:@"%@",string];
            [scrollView addSubview:messageLabel];
            
            UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
            numberLabel.font = [UIFont systemFontOfSize:13];
            numberLabel.text = [NSString stringWithFormat:@"%@",messageDic[string]];
            scrollView.contentSize = defectiveLabel.bounds.size;
            [scrollView addSubview:numberLabel];
            j++;
            
        }
        NSInteger  messageTotal = 0;
        for (NSString *string in messageDic) {
            messageTotal = messageTotal + [messageDic[string] intValue];
        }
        
        UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
        messageLabel.font = [UIFont systemFontOfSize:13];
        messageLabel.text = [THMangerTool language:@"show.totalCount"];
        [scrollView addSubview:messageLabel];
        
        UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
        numberLabel.font = [UIFont systemFontOfSize:13];
        numberLabel.text = [NSString stringWithFormat:@"%ld",messageTotal];
        [scrollView addSubview:numberLabel];
        j++;
        scrollView.contentSize = CGSizeMake(submitView.bounds.size.width, numberLabel.bottom);
        
        [defectiveView addSubview:scrollView];
    }
    
    // 确认和修改
    UIView *confirmView = [[UIView alloc]initWithFrame:CGRectMake(0, submitView.bounds.size.height - 38, submitView.bounds.size.width / 2 - 1, 40)];
    confirmView.backgroundColor = [UIColor whiteColor];
    [submitView addSubview:confirmView];
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmButton.frame = confirmView.bounds;//CGRectMake((confirmView.bounds.size.width - 50) / 2, (confirmView.bounds.size.height - 20) / 2, 50, 20);
    [confirmButton setTitle:[THMangerTool language:@"CreatingOrders.Confirm"] forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UtilCheck hexStringToColor:@"12a9d1" alpha:1] forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(confirm) forControlEvents:UIControlEventTouchUpInside];
    [confirmView addSubview:confirmButton];
    
    UIView *modifyView = [[UIView alloc]initWithFrame:CGRectMake(submitView.bounds.size.width / 2, submitView.bounds.size.height - 38, submitView.bounds.size.width / 2, 40)];
    modifyView.backgroundColor = [UIColor whiteColor];
    [submitView addSubview:modifyView];
    
    UIButton *modifyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    modifyButton.frame = modifyView.bounds;
    //CGRectMake((confirmView.bounds.size.width - 50) / 2, (confirmView.bounds.size.height - 20) / 2, 50, 20);
    [modifyButton setTitle:[THMangerTool language:@"CreatingOrders.Modify"] forState:UIControlStateNormal];
    [modifyButton setTitleColor:[UtilCheck hexStringToColor:@"12a9d1" alpha:1] forState:UIControlStateNormal];
    [modifyButton addTarget:self action:@selector(modify) forControlEvents:UIControlEventTouchUpInside];
    
    [modifyView addSubview:modifyButton];
    
//    }
    
}
#pragma  mark 确认提交
- (void)confirm{
    NSMutableArray *receiveGoodArray = [[NSMutableArray alloc]init];
    
    NSMutableDictionary *dataDictionary = [[NSMutableDictionary alloc]init];
    
    [replaceDataDic removeObjectForKey:@"name"];
    
    if ([replaceDataDic[@"isUrgent"] isEqualToString:[UtilCheck language:@"order.no"]] ) {
        [replaceDataDic setValue:@"false" forKey:@"isUrgent"];
    }else {
        [replaceDataDic setValue:@"true" forKey:@"isUrgent"];
    }

    
    NSArray *array = [replaceDataDic[@"tel"] componentsSeparatedByString:@" "];
    if (array.count > 1) {
        [replaceDataDic setValue:array[1] forKey:@"tel"];
    }
    [dataDictionary setValue:replaceDataDic forKey:@"receiveGood"];
    
    for (NSDictionary *dic in replaceArray) {
        
        NSMutableDictionary *tmpDict = [[NSMutableDictionary alloc]init];
        [tmpDict setValue:[dic objectForKey:@"rma"] forKey:@"rma"];
        [tmpDict setValue:[dic objectForKey:@"name"] forKey:@"name"];
        [tmpDict setValue:[dic objectForKey:@"id"] forKey:@"id"];
        [tmpDict setValue:[dic objectForKey:@"code"] forKey:@"code"];
        [tmpDict setValue:[dic objectForKey:@"version"] forKey:@"versionCode"];
        [tmpDict setValue:[dic objectForKey:@"number"] forKey:@"number"];
        [tmpDict setValue:[dic objectForKey:@"describe"] forKey:@"describe"];
        
        [receiveGoodArray addObject:tmpDict];
        
    }
    [dataDictionary setValue:receiveGoodArray forKey:@"failureParts"];
    
    if (self.dict != nil) {
        [dataDictionary setValue:self.dict[@"orderStatus"][@"orderCode"] forKey:@"orderCode"];
        
    }
    [dataDictionary setValue:@"1" forKey:@"orderType"];
    [dataDictionary setValue:[replaceLogisticsDic objectForKey:@"courierID"] forKey:@"courierID"];
    [dataDictionary setValue:[replaceLogisticsDic objectForKey:@"courierNum"] forKey:@"courierNum"];
    
    [dataDictionary setValue:message forKey:@"remark"];
    NSLog(@"wwwwwwwwwwwwwwwwwwwwwwwwwwww%@",dataDictionary);
    
    [[BDHUD sharedManager] showBDHUD:self.view title:nil];
    [AFHttpTool postJsonDatawithUrl:@"insertOrder_replace"  parameters:dataDictionary success:^(id responseObject) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if(1 == [[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]) {
            
            NSString *info = [[responseObject objectForKey:@"head"] objectForKey:@"info"];
            
            if ([UtilCheck DataIsNuLL:info]) {
                
                info = [UtilCheck language:@"setting.cogeAdd"];
            }
            [[BDHUD sharedManager] showWords:info];
            [self.navigationController popViewControllerAnimated:YES];
        
        }
        else {
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
        
    }];
}

#pragma  mark 继续修改
- (void)modify{
    [shadowView removeFromSuperview];
}

- (void)shadow{
    [shadowView removeFromSuperview];
}

@end
